FROM openjdk:21-jdk-slim

WORKDIR /app

# Install curl and download OpenTelemetry Java Agent
RUN apt-get update \
    && apt-get install -y --no-install-recommends curl \
    && rm -rf /var/lib/apt/lists/* \
    && curl -L -o opentelemetry-javaagent.jar \
    https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar

# Copy Maven wrapper and pom.xml
COPY mvnw .
COPY mvnw.cmd .
COPY .mvn .mvn
COPY pom.xml .

# Download dependencies
RUN ./mvnw dependency:go-offline -B

# Copy source code
COPY src src

# Build application
RUN ./mvnw clean package -DskipTests

# Run application with OpenTelemetry agent
EXPOSE 8080
CMD ["java", "-javaagent:opentelemetry-javaagent.jar", "-jar", "target/admin-backend-0.0.1-SNAPSHOT.jar"]
